package com.ljkj.blockpay.presenter;

import android.content.Context;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonList;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.basedata.BaseView;
import com.ljkj.blockpay.basedata.BuildConfig;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.AssetPresenterInter;

public class AssetPresenter extends BasePresenterImpl<AssetPresenterInter.AssetPresenterInterview> implements AssetPresenterInter.AssetPresenterInterPresenter{

    public AssetPresenter(@NonNull Context context, @NonNull AssetPresenterInter.AssetPresenterInterview view) {
        super(context, view);
    }

    @Override
    public void balanceInfo() {
        HttpRequest.GET(getContext(), ApiToCConfig.URL_BALANCE_INFO,
                new Parameter(),
                new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap jsonMap = main.getJsonMap("data");
                    getView().getbalanceInfo(jsonMap);
                }
            }
        });
    }

    /**
     * banner
     */
    @Override
    public void banner() {
        HttpRequest.POST(getContext(), ApiToCConfig.URL_BANNERLIST, new Parameter(), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonList mainList = main.getList("data");
                    getView().banner(mainList);

                }
            }
        });
    }

    /**
     * 收款二维码解析
     */
    @Override
    public void content(String qrcontent) {
        HttpRequest.GET(getContext(), ApiToCConfig.URL_CONTENT, new Parameter().add("content",qrcontent), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap data = main.getJsonMap("data");
                    getView().contentSuccess(data);

                }
            }
        });
    }
}
